﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace INIFILE
{
    class Profile
    {
        public static void LoadProfile()
        {
            string strPath = AppDomain.CurrentDomain.BaseDirectory;
            _file = new IniFile(strPath + "Cfg.ini");
            G_BAUDRATE = _file.ReadString("CONFIG", "BaudRate", "9600");    //读数据，下同
            G_DATABITS = _file.ReadString("CONFIG", "DataBits", "8");
            G_STOP = _file.ReadString("CONFIG", "StopBits", "1");
            G_PARITY = _file.ReadString("CONFIG", "Parity", "NONE");
            G_PORTNAME = _file.ReadString("CONFIG", "PortName", "COM8");
            G_CAMERA = _file.ReadString("CONFIG", "Camera", "No Camera");
            G_Folder = _file.ReadString("CONFIG", "Folder", "C:\\Users\\Administrator\\Pictures\\lottery");
            G_Timeout = _file.ReadString("CONFIG", "Timeout", "60000");//默认超时60秒
            G_ResolutionIndex = _file.ReadString("CONFIG", "ResolutionIndex", "0");
            G_CameraDelay = _file.ReadString("CONFIG", "CameraDelay", "1000");
        }

        public static void SaveProfile()
        {
            string strPath = AppDomain.CurrentDomain.BaseDirectory;
            _file = new IniFile(strPath + "Cfg.ini");
            _file.WriteString("CONFIG", "BaudRate", G_BAUDRATE);            //写数据，下同
            _file.WriteString("CONFIG", "DataBits", G_DATABITS);
            _file.WriteString("CONFIG", "StopBits", G_STOP);
            _file.WriteString("CONFIG", "Parity", G_PARITY);
            _file.WriteString("CONFIG", "PortName", G_PORTNAME);
            _file.WriteString("CONFIG", "Camera", G_CAMERA);
            _file.WriteString("CONFIG", "Folder", G_Folder);
            _file.WriteString("CONFIG", "Timeout", G_Timeout);
            _file.WriteString("CONFIG", "ResolutionIndex", G_ResolutionIndex);
            _file.WriteString("CONFIG", "CameraDelay", G_CameraDelay);
        }

        private static IniFile _file;//内置了一个对象

        public static string G_BAUDRATE ;//给ini文件赋新值，并且影响界面下拉框的显示
        public static string G_DATABITS ;
        public static string G_STOP ;
        public static string G_PARITY ;
        public static string G_PORTNAME ;

        public static string G_CAMERA ;
        public static string G_Folder ;
        public static string G_Timeout ;
        public static string G_ResolutionIndex;
        public static string G_CameraDelay;
    }
}
